// Registry.h
// (c) 2008, Charles Lechasseur
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#ifndef RRO_UTILS_REGISTRY_REGISTRY_H
#define RRO_UTILS_REGISTRY_REGISTRY_H

#pragma once

#include "Exceptions/Win32Exception.h"
#include <windows.h>

#pragma warning( push )
#pragma warning( disable : 4290 )   // C++ exception specification not supported.


namespace RRO
{
    //
    // Exception type thrown by failed registry calls.
    //
    class RegistryException : public Win32Exception
    {
    public:
        explicit                RegistryException(LONG p_ErrorCode);
                                RegistryException(const RegistryException& p_Exception);
        RegistryException&      operator=(const RegistryException& p_Exception);
        virtual                 ~RegistryException(void);

        const char*             what(void) const;
    };

    //
    // Simple helper class to store a registry key. The destructor will close the key.
    //
    class RegistryKey
    {
    public:
                        RegistryKey(void);
        explicit        RegistryKey(HKEY p_hKey);
                        ~RegistryKey(void);

        HKEY            Key(void) const;
                        operator HKEY(void) const;

        HKEY*           operator&(void);

    private:
        // The key.
        HKEY            m_hKey;

        // THESE METHODS ARE NOT IMPLEMENTED.
                        RegistryKey(const RegistryKey&);
        RegistryKey&    operator=(const RegistryKey&);
    };

    //
    // Helper class containing functions to deal with the registry.
    //
    class Registry
    {
    public:
        static void     SetStringValue(HKEY p_hBaseKey, const char* p_Path,
                                       const char* p_ValueName, const char* p_Value) throw (RegistryException);

        static void     DeleteKey(HKEY p_hBaseKey, const char* p_Path) throw (RegistryException);

    private:
        // THESE METHODS ARE NOT IMPLEMENTED.
                        Registry(void);
                        ~Registry(void);
    };

}; // namespace RRO


#pragma warning( pop )

#endif RRO_UTILS_REGISTRY_REGISTRY_H
